import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import java.io.*;

public class XMLUtilTV {

	public static String getBrandName(String type) {
		try { 
			// 创建文档对象
			DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
			DocumentBuilder builder = dFactory.newDocumentBuilder();
			Document doc;
			doc = builder.parse(new File("24Design/Simple_Factory_Pattern/configTV.xml"));
			//获取包含品牌名称的文本节点 
			NodeList nl = doc.getElementsByTagName("brandName");
			for(int i = 0;i < nl.getLength();i++) {
				String brandName = nl.item(i).getFirstChild().getNodeValue().trim();
				
				if(brandName.equals(type)) {		
					return brandName;
				}
			}
//			Node classNode = nl.item(0).getFirstChild();
//			String brandName = classNode.getNodeValue().trim();
			//return brandName;
			return null;
		} catch (Exception e) {
			e.printStackTrace();
			return null;

		}
		
	}
}
